//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "AtomicDefault.h"
using namespace Cephei::QL::Experimental::Credit;
#undef HANDLE
#undef ABSTRACT
#define STRUCT
Cephei::QL::Experimental::Credit::CAtomicDefault::CAtomicDefault (boost::shared_ptr<QuantLib::AtomicDefault>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAtomicDefault = NULL;
#endif
	_ppAtomicDefault = &childNative;
    
}
Cephei::QL::Experimental::Credit::CAtomicDefault::CAtomicDefault (QuantLib::AtomicDefault& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phAtomicDefault = NULL;
#endif
	_ppAtomicDefault = new boost::shared_ptr<QuantLib::AtomicDefault> (&childNative);
    
    _AtomicDefaultOwner = owner;
    
}

Cephei::QL::Experimental::Credit::CAtomicDefault::CAtomicDefault (CAtomicDefault^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAtomicDefault = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppAtomicDefault = new boost::shared_ptr<QuantLib::AtomicDefault> (copy->GetShared());
        
    }
}
Cephei::QL::Experimental::Credit::CAtomicDefault::CAtomicDefault (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAtomicDefault = NULL;
#endif
	if (!t->IsSubclassOf(CAtomicDefault::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Experimental::Credit::CAtomicDefault::CAtomicDefault (QuantLib::Handle<QuantLib::AtomicDefault>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phAtomicDefault = &childNative;
	_ppAtomicDefault = &static_cast<boost::shared_ptr<QuantLib::AtomicDefault>>(childNative.currentLink());
    
    _AtomicDefaultOwner = owner;
}
Cephei::QL::Experimental::Credit::CAtomicDefault::CAtomicDefault (QuantLib::Handle<QuantLib::AtomicDefault> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phAtomicDefault = &childNative;
	_ppAtomicDefault = &static_cast<boost::shared_ptr<QuantLib::AtomicDefault>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Experimental::Credit::CAtomicDefault::CAtomicDefault (QuantLib::AtomicDefault childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phAtomicDefault = NULL;
#endif
	_ppAtomicDefault = new boost::shared_ptr<QuantLib::AtomicDefault> (new QuantLib::AtomicDefault (childNative));
    
}
#endif

Cephei::QL::Experimental::Credit::CAtomicDefault::~CAtomicDefault ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppAtomicDefault != NULL)
    {
	    delete _ppAtomicDefault;
        _ppAtomicDefault = NULL;
    }
}
Cephei::QL::Experimental::Credit::CAtomicDefault::!CAtomicDefault ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppAtomicDefault != NULL)
    {
	    delete _ppAtomicDefault;
    }
}
QuantLib::AtomicDefault& Cephei::QL::Experimental::Credit::CAtomicDefault::GetReference ()
{
    if (_ppAtomicDefault == NULL) throw gcnew NativeNullException ();
	return **_ppAtomicDefault;
}
boost::shared_ptr<QuantLib::AtomicDefault>& Cephei::QL::Experimental::Credit::CAtomicDefault::GetShared ()
{
    if (_ppAtomicDefault == NULL) throw gcnew NativeNullException ();
	return *_ppAtomicDefault;
}
QuantLib::AtomicDefault* Cephei::QL::Experimental::Credit::CAtomicDefault::GetPointer ()
{
    if (_ppAtomicDefault == NULL) throw gcnew NativeNullException ();
	return &**_ppAtomicDefault;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::AtomicDefault>& Cephei::QL::Experimental::Credit::CAtomicDefault::GetHandle ()
{
	if (_phAtomicDefault == NULL)
	{
		_phAtomicDefault = new Handle<QuantLib::AtomicDefault> (*_ppAtomicDefault);
	}
	return *_phAtomicDefault;
}
#endif
bool Cephei::QL::Experimental::Credit::CAtomicDefault::HasNative () 
{
	return (_ppAtomicDefault != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

